﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace psafth.AMB.Objects
{
    public class StatusObject
    {
        /// <summary>
        /// Not sure if this really is a decoderid. 
        /// </summary>
        public ulong DecoderId
        {
            get;
            private set;
        }

        /// <summary>
        /// Input noise from the antenna
        /// </summary>
        public int Noise
        {
            get;
            private set;
        }

        /// <summary>
        /// Input voltage to the decoder
        /// </summary>
        public float InputVoltage
        {
            get;
            private set;
        }

        /// <summary>
        /// Temperature for the decoder
        /// </summary>
        public int Temperature
        {
            get;
            private set;
        }

        /// <summary>
        /// Constructs a StatusObject from the FOR
        /// </summary>
        /// <param name="fieldOfRecords"></param>
        public StatusObject(List<DataObject> fieldOfRecords)
        {
            foreach (DataObject record in fieldOfRecords)
            {
                switch (record.DataType)
                {
                    case (int)AMBGeneralFOR.DECODER_ID:
                        this.DecoderId = AMBCalculator.GetDecoderId(record.Data);
                        break;

                    case (int)AMBStatusFOR.NOISE:
                        this.Noise = (int)AMBCalculator.GetUlong(record.Data);
                        break;

                    case (int)AMBStatusFOR.INPUT_VOLTAGE:
                        this.InputVoltage = (float)AMBCalculator.GetUlong(record.Data) / 10;
                        break;

                    case (int)AMBStatusFOR.TEMPERATURE:
                        this.Temperature = (int)AMBCalculator.GetUlong(record.Data);
                        break;
                }
            }
        }
    }
}
